﻿using System;
using RaytracerLib.MathLib;
using RaytracerLib.Postprocessing.LightCorrector;
using RaytracerLib.Resamplers;
using RaytracerLib.Samplers;
using YAXLib;
using RaytracerLib.ShadowTesters;
using RaytracerLib.Attenuations;
using RaytracerLib.MathLib.Polynomials;
using RaytracerLib.MathLib.RootFinders;
using RaytracerLib.Cameras;
using RaytracerLib.Renderers;

namespace RaytracerLib
{
    public class RenderOptions
    {
        [YAXNode]
        public ColorFloat AmbientColor = ColorFloat.Black;

        [YAXNode]
        public double EnvironmentRefractionIndice = 1;

        [YAXNode]
        public long DebugBreakIntersectionID = 0;

        [YAXNode]
        public double DebugPixelX = -1;

        [YAXNode]
        public double DebugPixelY = -1;

        [YAXNode]
        public bool Parallel = true;

        [YAXNode]
        public double LightSpeed = 1;

        [YAXNode]
        public ShadowTestMethod ShadowTestMethod = ShadowTestMethod.AttenuationTransmittance;

        [YAXNode]
        public Attenuation EnvironmentAttenuation;

        [YAXNode(Default = false, OmitWhenDefault = true)]
        public bool HighPriority;

        [YAXNode]
        public Renderer Renderer = new BackwardRenderer();

        [YAXNode]
        public PolynomialSolveMethod PolynomialSolveMethod = PolynomialSolveMethod.Sturm;

        [YAXNode]
        public RootFindingMethod RootFindingMethod = RootFindingMethod.ModifedRegulaFalsi;

        [YAXNode(Default = 0, OmitWhenDefault = true)]
        public int RandomSeed;

        public void RenderStart(RenderStartPhase a_phase)
        {
            if (a_phase == RenderStartPhase.CheckForErrors)
            {
                if (RandomSeed == 0)
                    RandomSeed = System.Environment.TickCount;
            }

            if (a_phase == RenderStartPhase.SRGBToLinear)
                AmbientColor = Gamma.SRGBToLinear(AmbientColor);

            if (a_phase == RenderStartPhase.CalculateAttenuations)
            {
                if (EnvironmentAttenuation != null)
                    EnvironmentAttenuation.CalculateAttenuation(LightSpeed);
            }
        }
    }
}